package com.surprise.db.dao.join;

import org.springframework.stereotype.Repository;

import com.surprise.db.dao.SimpleDAO;
import com.surprise.db.entity.join.SelectSurpriseLike003Entity;

/**
 * SelectSurpriseLike003.java
 * @author xuling
 * @since 2017年9月28日
 */
@Repository
public class SelectSurpriseLike003 extends SimpleDAO<SelectSurpriseLike003Entity> {

	/**
	 * 根据商户ID，获得用户关注信息
	 * @param yesterday 昨天日期
	 * @param today 今天日期
	 * @param sevenDayStart 七天开始日期
	 * @param sevenDayEnd 七天结束日期
	 * @param shopid 商户ID
	 * @return 用户关注信息
	 */
	public SelectSurpriseLike003Entity select(String yesterday, String today, String sevenDayStart, String sevenDayEnd, Long shopid) {
		String sql = " SELECT yesterdayCount, todayCount, sevenDayCount, totalCount FROM " + 
				" (SELECT COUNT(id) as yesterdayCount from surprise_like where surprise_like.showDate = ? AND surprise_like.shopid = ?) as subQuery1," +
				" (SELECT COUNT(id) as todayCount from surprise_like where surprise_like.showDate = ? AND surprise_like.shopid = ?) as subQuery2," +
				" (SELECT COUNT(id) as sevenDayCount from surprise_like where surprise_like.showDate BETWEEN ? AND ? AND surprise_like.shopid = ?) as subQuery3," +
				" (SELECT COUNT(id) as totalCount from surprise_like WHERE surprise_like.shopid = ?) as subQuery4";
		return super.findOneBySql(sql, yesterday, shopid, today, shopid, sevenDayStart, sevenDayEnd, shopid, shopid);
	}
}
